home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / ldb.zip / LDB.DOC < prev    next >
Text File  |  1991-10-21  |  19KB  |  372 lines

  1.  
  2.  
  3. Dear C++ Programmer,
  4.  
  5.  
  6. Thank you for downloading the Loose Data Binder (LDB).  The LDB is
  7. a generic persistent container class that is less filling (smaller
  8. code sizes and faster execution) and less stuffy (no towering 
  9. convoluted hierarchies) than other conventional container class 
  10. libraries found packaged with C++ compilers and application 
  11. framework tools.
  12.  
  13. The LDB is offered to you as shareware, meaning try before you buy.
  14. For other than evaluation purposes directed at reaching a buy or 
  15. no buy decision, you are required by law to register the LDB.  A 
  16. hard copy manual will be sent to users upon receiving registration.
  17. The source code is also provided on either 3.5" or 5 1/4" DOS 
  18. diskette (please specify).  The source is broken down into many 
  19. files along with a makefile for library building.  PSW reserves 
  20. the right to withdraw this offer at any time.
  21.  
  22.     LDB v1.4  $30 in U.S.  $40 elsewhere
  23.     
  24.     Please make checks payable to:
  25.  
  26.         PSW / Power SoftWare
  27.         P.O. Box 10072
  28.         McLean, VA 22102 8072 USA
  29.  
  30. If you have questions about the LDB you can contact me at:
  31.  
  32.         John Small
  33.         Voice: (703) 759-3838
  34.         CIS: 73757,2233
  35.         Exec PC:  MSMALL
  36.         
  37. I have included tutorial chapter from the manual to get you
  38. started along with seven demos.
  39.  
  40.  
  41.                             Chapter 3
  42.  
  43.                             Tutorial
  44.  
  45.  
  46. Copy binder.hpp, sbinder.hpp, sdata.hpp, and cbinder.hpp to your
  47. compiler's standard header directory and the *.cpp files to your
  48. source code directory if you have not already done so.  Refer to
  49. the header file listings in the appendix for a quick reference to
  50. the various member functions of the LDB.  If a member function's
  51. operation is unclear, look up its entry in the reference chapter
  52. for an explanation.  Be sure to study the code of these examples,
  53. then compile (don't forget to link to binder.obj, sbinder.obj,
  54. sdata.obj and/or cbinder.obj as appropriate) and run them to see
  55. the results.  Are the results what you expected?  Okay let's begin. 
  56.  
  57.  
  58.                            BDRDEM1.CPP
  59.  
  60. This first example is a demo of the two Binder class constructors
  61. used in various configurations.  Find their declarations in
  62. binder.hpp or the reference chapter and make a mental note of their
  63. parameters and defaults!  I will only highlight some of their uses
  64. here.
  65.  
  66. Okay let's walk through the code of this first example which can of
  67. course be found in bdrdem1.cpp.  Starting in main() the first
  68. Binder, B1, is defined and constructed with all default parameters. 
  69. As you can see from binder.hpp, the binder is constructed with
  70. flags = BDR_NO_FREE, maxNodes = BDR_MAXNODES, limit = BDR_LIMIT,
  71. and delta = BDR_DELTA.  Don't worry about this stuff for now.  All
  72. we have here is a very basic binder behaving as an elastic array of
  73. void pointers which you supply.
  74.  
  75.      (see bdrdem1.cpp)  omitted here to reduce download size
  76.  
  77. The for loop inserts the char pointers of the vector V into the
  78. rear of the binder treating it as if it were a queue.  The loop is
  79. terminated when the NULL pointer of V is attempted to be inserted
  80. into the binder queue.  The insQ() primitive always returns the
  81. pointer it inserts into the binder and of course it's not going to
  82. ever insert the NULL pointer so voiD0, the NULL void pointer is
  83. returned to indicate failure!
  84.  
  85. Every binder can be treated as a list by internalizing the concept
  86. of some node being the current node.  When a binder is first
  87. created no node is current.  The stack, queue, deque, and array
  88. primitives don't affect the current node index, after all it is a
  89. list concept!  Instead the primitives ins(), del(), insSort(),
  90. next(), and prev(), etc. are the list primitives and they do affect
  91. the current node pointer.  The next() primitive advances the
  92. current index and returns the void pointer to that new current node
  93. if there is one.  I'm treating the returned pointer from next() in
  94. the example as a boolean value to test when I reach the end of the
  95. list.  One of the beauties (and pains) of C++ is that of overloaded
  96. operators.  The implicit type cast operator voiD simply returns the
  97. pointer to the current node.  You will soon notice that I have a
  98. habit of capitalizing the last letter of type names to indicate a
  99. pointer to that type.  Here voiD means a pointer to void.
  100.  
  101. Okay, enough hand holding, it's time to speed up!  The next binder,
  102. B2, is constructed so that it is limited to a maximum of 3 nodes. 
  103. Upon destruction of the binder all nodes will be deleted which is
  104. indicated by setting the flags parameter to BDR_OK_FREE.  The
  105. default parameter is BDR_NO_FREE which mean that nodes are simply
  106. released when the binder is destructed.  Furthermore the functions
  107. that attempt to delete nodes are inhibited, e.g. atFree().
  108. Notice the forEach() iterator and how it applies the block
  109. parameter to each element in the binder in sequential order.  Block
  110. is SmallTalk terminology for a function passed as a parameter
  111. (C/C++ programmers say function pointers).
  112.  
  113. The last binder of this example, B3, demonstrates the other
  114. constructor which takes a vector (array) of pointers and explodes
  115. them into a binder.  By explode, I mean each cell of the vector
  116. becomes a node in the binder.  Of course the original vector is
  117. left intact.  You can implode a binder back into a dynamically
  118. allocated vector which is returned by the vector() primitive.  The
  119. overloaded ++ operator simply applies the next() primitive to the
  120. binder.  Find the definition of operator++() in binder.hpp.
  121.  
  122.  
  123.                            BDRDEM2.CPP
  124.  
  125. In this second example, you will see several of the various stack,
  126. queue, list, array, and sort primitives in action.  This is only a
  127. sampling, see the class declaration of Binder in binder.hpp for a
  128. complete listing of primitives.  If you grasp the basic structure
  129. and operation of the binder here you can fill in the details from
  130. reading the header file.
  131.  
  132.      (see bdrdem2.cpp)  omitted here to reduce download size
  133.  
  134. With the first binder, B, of this example we see the primitive
  135. atIns() used.  A binder's cells are indexed from 0 to n - 1 just
  136. like a conventional C array of n cells.  AtIns() is not a list
  137. primitive, per say, and thus doesn't affect the binder's current
  138. node index.  When no node is current, the current node number is
  139. internally set to "nodes", one position pass the last element in
  140. the binder.  Primitives that search for a node returning its index
  141. will return BDR_NOTFOUND to indicate no node found.  What may seem 
  142. strange to you at first is that BDR_NOTFOUND is a large positive
  143. integer, the largest number of nodes that can ever be stored in a
  144. binder in fact.  Remember that one less than this number will be
  145. the last element's index in a completely filled binder.  
  146.  
  147. The second binder, B2, is filled with a sorted list of the nodes
  148. from binder B.  Now both B and B2 contain pointers to the same
  149. nodes!  This could be a potentially hazardous situation but since
  150. both binders don't delete their nodes upon destruction (flags =
  151. BDR_NO_FREE in constructor) nothing is accidently deleted twice
  152. or even once since nothing was allocated to begin with.
  153.  
  154.  
  155.                           SBDRDEM1.CPP
  156.  
  157. SBinder, derived from Binder and Streamable, is streamable or
  158. persistent in OOP's parlance.  In other words, an SBinder can be
  159. saved on a stream and reloaded later.  Streamable nodes have
  160. provisions for recording double ownerships and automatically
  161. safeguarding against accidental double deletions at the same time
  162. as providing streamability as we will see in this example.
  163.  
  164. A class must include the STREAMABLE macro in its public section and
  165. be derived either publicly or privately from Streamable but never
  166. virtually or otherwise multiply inherited in order for it to be
  167. "streamable" (see StreamableInt below).  If Streamable were allowed
  168. to be a virtual base class its pointer couldn't be type casted to
  169. its derived classes when reloading.  All that is known at reload
  170. time is that it's Streamable and you get back a Streamable class
  171. instance pointer.  The ID() member function must then be called to
  172. find out what